
    class Animal {
        public String name;
        public int age;
        public void eat() {
            System.out.println(this.name +"正在吃饭.....");
        }
        public Animal(String name,int age) {
            this.name = name;
            this.age = age;
        }
    }
    class Dog extends Animal {
        public void bark() {
            System.out.println(this.name +"正在汪汪叫....");
        }
        public void eat() {
            System.out.println(this.name +"正在吃狗粮.....");
        }
        public Dog(String name,int age) {
            super(name,age);
        }
    }
    class Cat extends Animal {
        public void fly() {
            System.out.println(this.name +"正在喵喵叫....");
        }
        public void eat() {
            System.out.println(this.name +"正在吃猫粮....");
        }
        public Cat(String name,int age) {
            super(name,age);
        }
    }

    public class Test {
        public static void func(Animal animal) {
            animal.eat();
        }
        public static Animal func2() {
            return new Dog("小修狗",4);//匿名对象，使用场景是 只使用一次这个对象
        }

        public static void main(String[] args) {
            //Dog dog = new Dog("小狗",3);
            //dog.age = 10;
            //dog.name = "小黄";
            //Cat cat = new Cat("小猫",2);
            Animal animal1 = new Dog("小狗",3);//发生了向上转型
            //animal1.eat();
            func(animal1);
            Animal animal2 = new Cat("小猫",2);//发生了向上转型
            //animal2.eat();
            func(animal2);
        }
    }
